/*
 * @Author: Huangdong
 * @Date: 2022-03-28 15:21:05
 * @LastEditors: minsheng_insurance_agency_zhoucl
 * @LastEditTime: 2025-11-18 08:43:00
 * @FilePath: \01.latest-short-insure\src\store\index.js
 * @Description:
 *
 *
 */
import Vue from "vue";
import Vuex from "vuex";
import createPersistedState from "vuex-persistedstate";

import modules from "./modules/index";

Vue.use(Vuex);

let showTimes = 0;
const timeStamp = new Date().getTime();
const config = {
  modules,
  plugins: [
    createPersistedState({
      key: "ms2024_insure",
      storage: window.sessionStorage,
    }),
  ],
  state: {
    workNum: "", // "岗位号",
    orderNum: "", // "订单号",
    mainRiskCode: "", // "主险编码",
    proIdCode: "", // 新增险种编码
    contractNum: "",
    gysEngName: "",
    yunUserId: "", //云服用户ID
    instype: "0", // 保单类型 0新单投保 1继续投保 2续保
    preOrderNum: "",
    vLoad: false, // 接口加载
    loadTxt: "数据加载中...",
    version: timeStamp.toString().slice(0, 6),
    token: "",
    /*ClickBeforeSurePop*/
    showPopTip: false, // 弹窗提示
    canClick: false, // 弹窗提示按钮点击
  },
  getters: {
    workNum: (state) => state.workNum,
    orderNum: (state) => state.orderNum,
    mainRiskCode: (state) => state.mainRiskCode,
    proIdCode: (state) => state.proIdCode,
    contractNum: (state) => state.contractNum,
    gysEngName: (state) => state.gysEngName,
    yunUserId: (state) => state.yunUserId,
    preOrderNum: (state) => state.preOrderNum,
    instype: (state) => state.instype,
    token: (state) => state.token,
    vLoad: (state) => state.vLoad,
    loadTxt: (state) => state.loadTxt,
    version: (state) => state.version,
    showPopTip: (state) => state.showPopTip,
    canClick: (state) => state.canClick,
  },
  mutations: {
    UPDATE_MAIN_STATE(state, payload) {
      Object.assign(state, payload);
    },
    updateLoad(state, payload) {
      // clearTime && clearTimeout(clearTime);
      if (payload) {
        showTimes++;
        if (window.isUniapp && showTimes == 1) return; // 避免异常未关闭 30s自动关闭
        // clearTime = setTimeout(function () {
        //   state.vLoad = false;
        // }, 30000);
      } else {
        state.loadTxt = "数据加载中";
      }
      state.vLoad = payload;
    },
    updateLoadTxt(state, payload) {
      state.loadTxt = payload;
    },
    updateToken(state, payload) {
      state.token = payload;
    },
    SET_WORK_NUM(state, payload) {
      state.workNum = payload;
    },
    SET_ORDER_NUM(state, payload) {
      state.orderNum = payload;
    },
    SET_MAIN_CODE(state, payload) {
      state.mainRiskCode = payload;
    },
    SET_ID_CODE(state, payload) {
      state.proIdCode = payload;
    },
    SET_CONTRACT_NUM(state, payload) {
      state.contractNum = payload;
    },
    SET_ENG_GYS(state, payload) {
      state.gysEngName = payload;
    },
    SET_YUN_UID(state, payload) {
      state.yunUserId = payload;
    },
    SET_INS_TYPE(state, payload) {
      state.instype = payload;
    },
    SET_PREORDER_NUM(state, payload) {
      state.preOrderNum = payload;
    },
  },
  actions: {
    openSurePop({ commit }) {
      commit("UPDATE_MAIN_STATE", {
        showPopTip: true,
      });
      setTimeout(() => {
        commit("UPDATE_MAIN_STATE", {
          canClick: true,
        });
      }, 3000);
    },
  },
};
const store = new Vuex.Store(config);
export default store;
